package com.lzmpt.imchat.ui.chatactivity;

import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.hyphenate.EMCallBack;
import com.lzmpt.imchat.DemoHelper;
import com.lzmpt.imchat.R;
import com.lzmpt.imchat.base.BaseChatActivity;
import com.lzmpt.imchat.ui.LoginActivity;
import com.lzmpt.imchat.ui.MainActivity;

public class SettingContactActivity extends BaseChatActivity implements View.OnClickListener {

    @Override
    public int initLayout() {
        return R.layout.activity_setting_contact;
    }

    @Override
    protected void setUpView() {
        setTitle("设置");
    }

    @Override
    protected void initView() {
        findViewById(R.id.ll_user_setting_code).setOnClickListener(this);
        findViewById(R.id.ll_user_setting_about).setOnClickListener(this);
        findViewById(R.id.tv_user_logout).setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.tv_user_logout) {
            logout();
        } else if (v.getId() == R.id.ll_user_setting_code) {
            startActivity(new Intent(SettingContactActivity.this, MyQRCodeActivity.class));
        } else {
            startActivity(new Intent(SettingContactActivity.this, AboutActivity.class));
        }
    }

    void logout() {
        final ProgressDialog pd = new ProgressDialog(getActivity());
        String st = getResources().getString(R.string.Are_logged_out);
        pd.setMessage(st);
        pd.setCanceledOnTouchOutside(false);
        pd.show();
        DemoHelper.getInstance().logout(true, new EMCallBack() {

            @Override
            public void onSuccess() {
                getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        // show login screen
                        try {
                            Class clazz = Class.forName("com.lzm.ydpt.LoginActivity");
                            getActivity().finish();
                            startActivity(new Intent(getActivity(), clazz));
                        } catch (ClassNotFoundException e) {
                            e.printStackTrace();
                        }


                    }
                });
            }

            @Override
            public void onProgress(int progress, String status) {

            }

            @Override
            public void onError(int code, String message) {
                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        pd.dismiss();
//                        Toast.makeText(getActivity(), "unbind devicetokens failed", Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });
    }

}
